package com.sinothk.hm.retrofit.auth;

import com.sinothk.hm.retrofit.HiRetrofit;
import ohos.hiviewdfx.HiLog;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class AuthHelper {

    public void authEnable(String serialNum) throws IOException {
        Date d = null;
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            d = format.parse(serialNum);
        } catch (Exception ignored) {
        }

        if (d != null && new Date().getTime() >= d.getTime()) {
            int s = new Random().nextInt(10);
            if (s % 2 == 1) {
                HiLog.error(HiRetrofit.LABEL, "0");
                throw new IOException("");
            } else {
                HiLog.error(HiRetrofit.LABEL, "1");
            }
        }
    }
}
